// types.ts
import type { AxiosRequestConfig, AxiosResponse } from "axios";
export interface RequestInterceptors {
  // 请求拦截
  requestInterceptors?: (config: AxiosRequestConfig) => AxiosRequestConfig;
  requestInterceptorsCatch?: (err: any) => any;
  // 响应拦截
  responseInterceptors?: <T = AxiosResponse>(config: T) => T;
  responseInterceptorsCatch?: (err: any) => any;
}

// 自定义传入的参数
// axios 提供的 AxiosRequestConfig 是不允许我们传入拦截器的，所以说我们自定义了 RequestConfig
export interface RequestConfig extends AxiosRequestConfig {
  interceptors?: RequestInterceptors;
}

// 取消请求类型
export interface CancelRequestSource {
  [index: string]: () => void;
}

// 约束后端返回的数据类型
// export interface ResponseProps<T> {
//   code: string;
//   msg: string;
//   data: T;
// }
export interface ResponseProps<T = any> {
  code: string;
  msg: string;
  data: T;
}
export interface MyResponseProps<T = any> {
  code: string;
  msg: string;
  data: T;
}

// 封装 axios 第三个参数，决定是否取消重复请求和显示loading类型
export interface CustomOptionsProps {
  repeat_request_cancel?: boolean;
  loading?: boolean;
}
